Repository navigation
feat(csharp): writer seams for DbContext hooks, framework names at emit, quiet regen - #683
Merged
Merged
Conversation
…it, quiet regen - Generators write framework references through CSharpNaming.Framework / FrameworkPrefix (or the generator's Fx prefix), so output is right as emitted. The runner no longer rewrites System./Microsoft. to global:: in every .cs file; it keeps a check that names a file still writing a bare reference a generated namespace shadows. - DbContextGenerator: a CsWriter overload for every statement hook (OwnedTypeConfig, FieldTypeConfig, DbColumnTypeConfig, DefaultValueConfig, ReferenceConfig, TphSubtypeFieldConfig, EntityConfigTrailer, EmitCheckConfig, DbSetLine, ContextMemberLines, ContextPreambleLines, ContextTrailerLines). Each defaults to its text hook; output and ConfigureModelNN splits are unchanged unless one is overridden, and a writer entry is never split. - Fr019SharedEnum.ProvidedEnumNamespace(SharedEnum, GenConfig) is public and is what SharedEnumTypeReference uses. - An object-typed field left off a view class is no longer warned on every gen; dotnet meta verify lists each once with its fix.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Changed
System.…,Microsoft.…) throughCSharpNaming.Framework/FrameworkPrefixat emit. The runner no longer rewrites output withglobal::. It now warns on a bare reference that a generated namespace shadows, and the output of a run stays byte-identical.DbContextGeneratortext hooks (OwnedTypeConfig,FieldTypeConfig,DbSetLine,ContextPreambleLines,EntityConfigTrailerand others) gainCsWriteroverloads. Each defaults to its string hook, so existing overrides keep working.Fr019SharedEnum.ProvidedEnumNamespace(SharedEnum, GenConfig)is public, andSharedEnumTypeReferencecalls it.gen.verifynow reports each such field once, with a fix hint.Validation
Risk Assessment
✅ Low: Changes are additive writer seams, emit-time framework qualification (output is byte-identical through the runner, backed by a shadow-check warning), and a verify-only advisory. Both fix-round changes (unwrapping HandEditsGenerator and honouring Include; body-only hook fragments) are correct and covered by tests that execute the real code.
Testing
Drove three scenarios live against the built C# codegen on a disposable model. Verify prints the object-typed projection advisory once with its fix hint; gen (first, unchanged, and forced) prints nothing; the wrapped-generator verify still warns. All pass. The C# conformance gate lane was not re-run in this step; the baseline affected run passed at this commit. Scratch files removed; worktree clean.
Evidence: Live gen/verify transcript, object-typed projection
Evidence: Live verify/gen transcript, wrapped EntityGenerator
Pipeline
Updates from git push no-mistakes
✅ **Intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
server/csharp/MetaObjects.Codegen/Generators/EntityGenerator.cs:316-UnemittedObjectFieldschecks for the entity generator withgenerators.Any(g => g is EntityGenerator). An entry wrapped by the documentednew EntityGenerator().WithHandEdits(HandEdits.Overwrite)is an internalHandEditsGenerator, so the check fails. Generation still drops the field from the view class, but verify then reports nothing. This change also removed the per-regenctx.Warn, so for those projects the skip becomes completely silent, which defeats finding 13's 'report it once with a fix hint'. The function also ignores each entity generator'sInclude, so verify can report projections that generator never emits. Fix: unwrap withg is HandEditsGenerator h ? h.Inner : g(asCodegenCli.Unwrappeddoes), take theEntityGeneratorinstances, and report an object only when one of them has a nullIncludeor one that accepts the object. Both call sites use this one function:server/csharp/MetaObjects.Cli/VerifyCommand.cs:516andserver/csharp/MetaObjects.Codegen/CodegenCli.cs:1102.server/csharp/MetaObjects.Codegen/Generators/DbContextGenerator.cs:110-HookEntries(around line 133) renders a writer-hook fragment withfragment.ToString().CsWriter.Body()puts the writer's header and using block in front of the body. An override that callsw.Using(...), or aNewWriter()override whose writer prints a header, therefore putsusing X;(or the header) insideOnModelCreatingor the class body, and theusingline does not compile. The comment at line 110 says the opposite ('a fragment writer's own using block is not carried over'). Either render only the base body (a protected or internal body-only accessor onCsWriter, or a plainCodeWriterfor fragments), or reject a fragment that has usings and nameContextUsings. At minimum, correct the comment.server/csharp/MetaObjects.Codegen/Generators/NamesGenerator.cs:42- The newFxproperty was inserted betweenGenerate's XML doc (Pass 1 / Pass 2) and the method.Fxthen had two<summary>blocks andGeneratehad none. I moved theFxproperty and its doc aboveGenerate's doc.server/csharp/MetaObjects.Codegen/Generators/FilterAllowlistGenerator.cs:75- The 'FR-044 — a served report joins the set…' comment that belongs toGeneratesat above the newFxproperty's doc. I moved it back to just aboveGenerate.server/csharp/MetaObjects.Codegen/Generators/RoutesGenerator.cs:98- The 'FR-044 — a served report joins the set as its ROW MODEL…' comment that describesGeneratesat above the newFxproperty's doc. I moved it back to just aboveGenerate.🔧 Fix applied.
📝 3 wording or comment-placement notes left for the author (no fix round spent):
server/csharp/MetaObjects.Codegen/Generators/NamesGenerator.cs:42- The newFxproperty was inserted betweenGenerate's XML doc (Pass 1 / Pass 2) and the method.Fxthen had two<summary>blocks andGeneratehad none. I moved theFxproperty and its doc aboveGenerate's doc.server/csharp/MetaObjects.Codegen/Generators/FilterAllowlistGenerator.cs:75- The 'FR-044 — a served report joins the set…' comment that belongs toGeneratesat above the newFxproperty's doc. I moved it back to just aboveGenerate.server/csharp/MetaObjects.Codegen/Generators/RoutesGenerator.cs:98- The 'FR-044 — a served report joins the set as its ROW MODEL…' comment that describesGeneratesat above the newFxproperty's doc. I moved it back to just aboveGenerate.🔧 **Test** - 3 issues found → no changes applied ✅
server/csharp/MetaObjects.Codegen/Generators/EntityGenerator.cs:314- Live scenario not driven: the intent's item 13 (object-typed projection advisory prints once ondotnet meta verify, nothing ongen) and item 8/9/10/11 CLI output were only covered by in-process focused tests, which are not live. Needs a disposable fixture run ofdotnet meta verifyanddotnet meta gento confirm the once-per-verify behaviour.dotnet meta verifyon a projection with an object-typed field prints the advisory once with its fix hint, Live:dotnet meta genon the same model prints no advisory on regenscripts/ci-local.sh --only csharp, which executes the dotnet test suites in-process. Not a live product run, so no pass is recorded.dotnet meta verifyon a projection with an object-typed field prints the advisory once with its fix hintdotnet meta genon the same model prints no advisory on regenscripts/ci-local.sh --affected --strict-toolchainsscripts/ci-local.sh --affected --strict-toolchains(baseline failure: conformance: csharp; other lanes green)scripts/ci-local.sh --only csharpbefore fix (eject contract tests failed: CS0122 inaccessible HandEditsGenerator, CsWriter.BodyOnly not found)dotnet testEjectContractTests and EjectedGeneratorsAloneTests (engine-surface check failed on GeneratorExtensions reference; fixed by moving unwrap to callers)scripts/ci-local.sh --only csharpafter fix: LOCAL CI PASSED (Conformance 2946, Render 372, Codegen 2076 pass/1 skipped, Cli 504, IntegrationTests 549). In-process test run, not live.Not run: livedotnet meta verify/genon a fixture (advisory once-per-verify, no-output-on-gen for item 13). Not run: full repo-wide regression suite (only C# lane and affected lanes from the gate).🔧 No changes applied.
✅ Re-checked - no issues remain.
scripts/ci-local.sh --affected --strict-toolchainsScratch C# project outside the repository (removed afterwards) referencing server/csharp/MetaObjects.Codegen, generator list [EntityGenerator], model acme::shop: object.value Address, object.entity Order (table, shipTo field.object @objectRef Address @storage jsonb), object.projection OrderSummary (view, shipTo extends Order.shipTo)dotnet run --project codegen -- gen --out generated(first run and unchanged regen)dotnet run --project codegen -- gen --force --out generateddotnet run --project codegen -- verify --codegen --out generatedSame gen/verify with generator wrapped inWithHandEdits(HandEdits.Overwrite)(env WRAPPED=1)Transcripts: evidence cs-live-object-projection.log and cs-live-wrapped-generator.logBaseline configured commandscripts/ci-local.sh --affected --strict-toolchainsalready passed at this commit (not re-run here)docs/ports/csharp.md- Docs for the C# change checked against diff: CHANGELOG 1.3.0 entries, docs/ports/csharp.md framework-name, CsWriter-overload and UseIdentityStartMigrations sections, CONFORMANCE global:: note, agent-context reference. All still accurate. Added one sentence to docs/ports/csharp.md (verify advisory for skipped object-typed fields on projections/read models). Remaining: agent-context csharp.md (and its shipped and fixture copies) does not mention the new CsWriter overloads; the text still holds, so left unchanged to avoid regenerating shipped copies.✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.
Validated in one no-mistakes run.